home *** CD-ROM | disk | FTP | other *** search
/ HyperLib 1997 Winter - Disc 1 / HYPERLIB-1997-Winter-CD1.ISO.7z / HYPERLIB-1997-Winter-CD1.ISO / オンラインウェア / COM / ProTERM Mac1.2a.sit / ProTERM Mac1.2a / Macros / Contributed / Greg's Extras / Index Maker < prev   
Text File  |  1996-04-24  |  2KB  |  108 lines

  1. // auto-index documentation builder
  2. FUNC main()
  3. {
  4.  INT width;
  5.  INT inp,out;
  6.  STR index,info;
  7.  STR fsrc,fdst;
  8.  
  9.  FN_SETPATH(7,FN_RESOLVE("",".APPL:");
  10.  FN_SETSPR(7,1);
  11.  fsrc = FN_OPEN(7,"Convert","TEXT");
  12.  IF (fsrc == "") { RETURN }
  13.  
  14.  FN_SETPATH(7,FN_RESOLVE("",".PREF:Additions:");
  15.  FN_SETSPR(7,1);
  16.  fdst = FN_SAVE(7,"Save Indexed Document As","Untitled");
  17.  IF (fdst == "") { RETURN }
  18.  
  19.  F_DELETE(fdst+".txt");
  20.  F_CREATE(fdst+".txt");
  21.  out = F_OPEN(fdst+".txt","RW");
  22.  inp = F_OPEN(fsrc,"RO");
  23.  IO_COPY(inp,out,"");
  24.  F_CLOSE(inp);
  25.  F_CLOSE(out); 
  26.  info = F_GETINFO(fdst+".txt");
  27.  info = STR_LEFT(info,2)+"ttro"+STR_MID(info,6);
  28.  F_SETINFO(fdst+".txt",info);
  29.  
  30.  inp = F_OPEN(fdst+".txt","RO");
  31.  index = make_index(inp);
  32.  F_CLOSE(inp);
  33.  
  34.  F_DELETE(fdst);
  35.  F_CREATE(fdst);
  36.  out = F_OPEN(fdst,"RW");
  37.  IF (out == 0) { RETURN }
  38.  
  39.  inp = F_OPEN(".PREF:Additions:%PT Indexor","RO");
  40.  IF (inp <= 0) {
  41.   WIN_NOTE(1,"Cannot locate .PREF:Additions:%PT Indexor");
  42.   RETURN;
  43.  }
  44.  IO_COPY(inp,out,"");
  45.  F_CLOSE(inp);
  46.  
  47.  IO_PRINTF(out,"FUNC index() { RETURN (^m");
  48.  
  49.  WHILE (index != "") {
  50.   width = 32;
  51.   IO_PRINTF(out,'$"');
  52.   DO {
  53.    IO_PRINTF(out,"%*2x",NUM_BYTE(index));
  54.    index = STR_MID(index,1);
  55.    IF (index == "") { BREAK }
  56.    width = width - 1;
  57.   } WHILE (width > 0);
  58.   IO_PRINTF(out,'"+^m');
  59.  }
  60.  
  61.  IO_PRINTF(out,'""); }^m');
  62.  F_CLOSE(out);
  63.  RETURN;
  64. }
  65.  
  66.  
  67.  
  68.  
  69. FUNC make_index(INT fd)
  70. {
  71.  INT left,right;
  72.  INT maxind,indent;
  73.  STR line;
  74.  STR index;
  75.  
  76.  maxind = 0;
  77.  index = "";
  78.  WHILE (1) {
  79.   IO_COPY(fd,0,"*");
  80.   left = IO_GETPOS(fd)-1;
  81.   IF (!IO_SCANF(fd,"%s^m",line)) { BREAK }
  82.   right = IO_GETPOS(fd)-1;
  83.   IF (STR_RIGHT(line,1) != "*") { CONTINUE }
  84.  
  85.   indent = 0;
  86.   WHILE (STR_LEFT(line,1) == "*") {
  87.    line = STR_MID(line,1);
  88.   }
  89.   line = STR_MID(line,1);
  90.   WHILE (STR_RIGHT(line,1) == "*") {
  91.    line = STR_LEFT(line,STR_LEN(line)-1);
  92.    indent = indent + 1;
  93.   }
  94.   line = STR_LEFT(line,STR_LEN(line)-1);
  95.  
  96.   IF (line == "stop") { BREAK }
  97.   IF (maxind == 0) { maxind = indent }
  98.  
  99.   index = index + STR_BYTE(STR_LEN(line)+12) +
  100.           $"f2" + STR_BYTE((maxind-indent)*2+1) + $"f108" +
  101.           STR_LONG(left) + STR_LONG(right) + 
  102.           STR_REPEAT(line,35);
  103.  }
  104.  index = STR_LONG(STR_LEN(index)/48)+STR_LONG(48)+index;
  105.  RETURN(index);
  106. }
  107.  
  108.